using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.Shake;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class ShakePeopleInfo : BasePage
	{
		private const string TAG = "ShakePeopleInfo";
		public ShakePeople shakePeople;
		private EventWatcher mWatcherSayHi;
		private EventWatcher mWatcherHeadImgAdd;
		private EventWatcher mWatcherExpose;
		private EventWatcher mWatcherVerifyIcon;
		private string mStrSayHiOrigin = "";
		private bool mBHasBrandListCtrl;
		private ProfileBrandListCtrl brandListCtrl;
		internal Grid LayoutRoot;
		internal StackPanel panelProfile;
		internal ProfileTopInfoCtrl topInfoCtrl;
		internal StackPanel panelContentInfo;
		internal Grid panelAblum;
		internal ProfileTxtContentCtrl ctrlArea;
		internal Button btnSendInvite;
		internal Button btnExpose;
		private bool _contentLoaded;
		public ShakePeopleInfo()
		{
			this.InitializeComponent();
			this.SetAppBar();
			base.add_Loaded(new RoutedEventHandler(this.ShakePeopleInfo_Loaded));
		}
		private void ShakePeopleInfo_Loaded(object sender, RoutedEventArgs e)
		{
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && 1 == object_0.Length)
			{
				if (object_0[0] != null && object_0[0] is ShakePeople)
				{
					this.shakePeople = (object_0[0] as ShakePeople);
				}
				this.initEventWatcher();
				this.InitUI(this.shakePeople);
				return;
			}
			base.GoBack();
		}
		protected override void OnPageOut()
		{
			this.unInitEventWatcher();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				ProfileBrandListCtrl.PushOneItem(this.brandListCtrl);
			});
		}
		private void initEventWatcher()
		{
			if (this.mWatcherSayHi == null)
			{
				this.mWatcherSayHi = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerLbsSayHi));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SHAKE_SAYHI_SUCCESS, this.mWatcherSayHi);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_SHAKE_SAYHI_ERR, this.mWatcherSayHi);
			}
			if (this.mWatcherHeadImgAdd == null)
			{
				this.mWatcherHeadImgAdd = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerHeadImgAdd));
				EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
			}
			if (this.mWatcherExpose == null)
			{
				this.mWatcherExpose = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerExpose));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_EXPOSE_SUCCESS, this.mWatcherExpose);
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_EXPOSE_ERR, this.mWatcherExpose);
			}
			if (this.mWatcherVerifyIcon == null)
			{
				this.mWatcherVerifyIcon = new EventWatcher(this, null, new EventHandlerDelegate(this.onVerifyFlagEventHandler));
				EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_VUSERINFO_UPDATED, this.mWatcherVerifyIcon);
			}
		}
		private void unInitEventWatcher()
		{
			if (this.mWatcherSayHi != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SHAKE_SAYHI_SUCCESS, this.mWatcherSayHi);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_SHAKE_SAYHI_ERR, this.mWatcherSayHi);
			}
			if (this.mWatcherHeadImgAdd != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
				this.mWatcherHeadImgAdd = null;
			}
			if (this.mWatcherExpose != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_EXPOSE_SUCCESS, this.mWatcherExpose);
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_EXPOSE_ERR, this.mWatcherExpose);
				this.mWatcherExpose = null;
			}
			if (this.mWatcherVerifyIcon != null)
			{
				EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_VUSERINFO_UPDATED, this.mWatcherVerifyIcon);
				this.mWatcherVerifyIcon = null;
			}
		}
		private void onVerifyFlagEventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
		}
		private void onEventHandlerLbsSayHi(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (EventConst.ON_NETSCENE_SHAKE_SAYHI_SUCCESS == evtArgs.mEventID)
			{
				MessageBoxManager.ShowToast(strings.Lbs_PeoInfo_MsgSayHiSucc, 2500, null, false);
				Log.smethod_5("ShakePeopleInfo", "ON_NETSCENE_SHAKE_SAYHI_SUCCESS");
				return;
			}
			if (EventConst.ON_NETSCENE_SHAKE_SAYHI_ERR == evtArgs.mEventID && evtArgs.mObject != null)
			{
				RetConst retConst = (RetConst)evtArgs.mObject;
				if (RetConst.MM_ERR_CLIENT == retConst)
				{
					MMMessageBox.Show(strings.Con_Detail_MsgBadNet, true, "确定");
				}
				else
				{
					if (RetConst.MM_ERR_SPAM == retConst)
					{
						MMMessageBox.Show(strings.Con_Detail_MsgSpam, true, "确定");
					}
					else
					{
						if (RetConst.MM_ERR_FREQ_LIMITED == retConst)
						{
							MMMessageBox.Show(strings.Lbs_PeoInfo_MsgTooFreq, true, "确定");
						}
						else
						{
							if (RetConst.MM_ERR_LBSBANBYEXPOSE == retConst)
							{
								MMMessageBox.Show(strings.Lbs_PeoInfo_MsgBadMan, true, "确定");
							}
							else
							{
								if (RetConst.MM_ERR_BLACKLIST == retConst)
								{
									MMMessageBox.Show(strings.Lbs_PeoInfo_MsgBeBlocked, true, "确定");
								}
								else
								{
									MMMessageBox.Show(strings.Con_Detail_MsgSendFailed, true, "确定");
								}
							}
						}
					}
				}
				Log.smethod_5("ShakePeopleInfo", "ON_NETSCENE_SHAKE_SAYHI_ERR:" + retConst);
			}
		}
		private void onEventHandlerHeadImgAdd(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(string) && current == this.shakePeople.strUserName)
					{
						this.topInfoCtrl.imgHead.set_Source(HeadImgMgr.getHeadImage(this.shakePeople));
					}
				}
			}
		}
		private void onEventHandlerExpose(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (evtArgs == null)
			{
				return;
			}
			if (EventConst.ON_NETSCENE_EXPOSE_SUCCESS == evtArgs.mEventID)
			{
				MessageBoxManager.ShowToast(strings.Lbs_PeoInfo_MsgExposeSucc, 2500, null, false);
				return;
			}
			if (EventConst.ON_NETSCENE_EXPOSE_ERR == evtArgs.mEventID)
			{
				MMMessageBox.Show(strings.Lbs_PeoInfo_MsgExposeFail, true, "确定");
			}
		}
		private void InitUI(ShakePeople shakePeople)
		{
			if (shakePeople != null)
			{
				this.topInfoCtrl.imgHead.set_Source(HeadImgMgr.getCacheHeadImage(shakePeople));
				this.topInfoCtrl.txtNicks.Text = shakePeople.strNickName;
				this.topInfoCtrl.SetSignature(shakePeople.strSignature);
				string regionShow = ToolFunction.GetRegionShow(shakePeople.strProvince, shakePeople.strCity);
				this.ctrlArea.InfoData = ProfileDataMgr.GetAreaInfo(regionShow);
				this.topInfoCtrl.SetSex(shakePeople.nSex);
				this.disAblum();
				this.disBrandList();
				this.topInfoCtrl.SetRequestStr(shakePeople.strDistance);
			}
		}
		private void topInfoCtrl_mImgHeadClicked(object sender, object args)
		{
			if (this.shakePeople != null && this.shakePeople.strUserName != null)
			{
				HDheadImgMgr.setHasHDheadImg(this.shakePeople.strUserName, this.shakePeople.bHasHDImg);
				base.GoToPage("/Source/UI/Contact/HighQualityHeadImgView.xaml", new object[]
				{
					args,
					this.shakePeople.strUserName,
					sender
				}, false);
				return;
			}
		}
		private void btnSayHi_Click(object sender, RoutedEventArgs e)
		{
			Dialog2BtnWithInputBox.Show(strings.Lbs_PeoInfo_MsgSayHiTitle, strings.Lbs_PeoInfo_MsgSayHiContent, strings.COM_Send, strings.COM_Cancel, "", new Dialog2BtnWithInputBox.dismissWithClickBtn(this.SayHiDialogHandler), new TextChangedEventHandler(this.SayHiInputChangedHandler), null);
		}
		private void btnExpose_Click(object sender, RoutedEventArgs e)
		{
			MMMessageBox mMMessageBox = MMMessageBox.Show(strings.Lbs_PeoInfo_MsgExposeTitle, strings.Lbs_PeoInfo_MsgExposeContent, false, strings.COM_Yes, strings.COM_No);
			mMMessageBox.ReturnEvent = new DlgReturnEvent(this.msgBoxExposeHandler);
		}
		public void msgBoxExposeHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			if (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0) == 0)
			{
				ServiceCenter.sceneExpose.doScene(this.shakePeople.strUserName, ExposeScene.MM_EXPOSE_SHAKE_SEARCH, 0u);
			}
		}
		private void SayHiInputChangedHandler(object sender, TextChangedEventArgs e)
		{
			if (sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				if (ToolFunction.getStrDisLen(dialog2BtnWithInputBox.txtIn.get_Text()) <= 20)
				{
					dialog2BtnWithInputBox.btnLeft.set_IsEnabled(true);
					this.mStrSayHiOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
					return;
				}
				if (this.mStrSayHiOrigin != null && this.mStrSayHiOrigin.get_Length() < dialog2BtnWithInputBox.txtIn.get_Text().get_Length())
				{
					dialog2BtnWithInputBox.txtIn.set_Text(this.mStrSayHiOrigin);
					dialog2BtnWithInputBox.txtIn.set_SelectionStart(dialog2BtnWithInputBox.txtIn.get_Text().get_Length());
				}
				this.mStrSayHiOrigin = dialog2BtnWithInputBox.txtIn.get_Text();
			}
		}
		private void SayHiDialogHandler(object sender, int nClickIndex)
		{
			if (nClickIndex == 0 && sender != null && sender is Dialog2BtnWithInputBox)
			{
				Dialog2BtnWithInputBox dialog2BtnWithInputBox = sender as Dialog2BtnWithInputBox;
				string text = dialog2BtnWithInputBox.txtIn.get_Text();
				if (text != null)
				{
					int arg_2A_0 = text.get_Length();
				}
				Shake.getInstance().sceneShakeService.doSayHi(this.shakePeople.strUserName, text);
			}
		}
		public void SetAppBar()
		{
			base.set_ApplicationBar(new ApplicationBar());
			ApplicationBarMenuItem applicationBarMenuItem = new ApplicationBarMenuItem(strings.Lbs_PeoInfo_BtnExpose);
			applicationBarMenuItem.add_Click(new EventHandler(this.ExposeMenuItem_Click));
			base.get_ApplicationBar().get_MenuItems().Add(applicationBarMenuItem);
			this.setAppBarStyle(base.get_ApplicationBar());
		}
		private void ExposeMenuItem_Click(object sender, EventArgs e)
		{
			this.btnExpose_Click(null, null);
		}
		private void disAblum()
		{
			if (this.shakePeople != null && this.shakePeople.nSnsFlag == 1u)
			{
				ProfileAblumCtrl profileAblumCtrl = new ProfileAblumCtrl();
				this.panelAblum.get_Children().Add(profileAblumCtrl);
				Contact contact = StorageMgr.contact.method_0(this.shakePeople.strUserName);
				if (contact == null)
				{
					contact = new Contact
					{
						strUsrName = this.shakePeople.strUserName,
						strNickName = this.shakePeople.strNickName,
						nSnsBGObjectID = this.shakePeople.nSnsBGObjectID,
						strSnsBGImgID = this.shakePeople.strSnsBGImgID,
						nSnsFlag = this.shakePeople.nSnsFlag,
						nSource = new uint?(26u)
					};
				}
				profileAblumCtrl.ItemObject = contact;
			}
		}
		private void disBrandList()
		{
			if (this.mBHasBrandListCtrl)
			{
				return;
			}
			if (this.shakePeople != null && !string.IsNullOrEmpty(this.shakePeople.strMyBrandList))
			{
				this.brandListCtrl = ProfileBrandListCtrl.GetOneItem();
				this.panelContentInfo.get_Children().Insert(1, this.brandListCtrl);
				this.mBHasBrandListCtrl = true;
				this.brandListCtrl.ItemObject = new Contact
				{
					strUsrName = this.shakePeople.strUserName,
					strMyBrandList = this.shakePeople.strMyBrandList
				};
			}
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Shake/UI/ShakePeopleInfo.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelProfile = (StackPanel)base.FindName("panelProfile");
			this.topInfoCtrl = (ProfileTopInfoCtrl)base.FindName("topInfoCtrl");
			this.panelContentInfo = (StackPanel)base.FindName("panelContentInfo");
			this.panelAblum = (Grid)base.FindName("panelAblum");
			this.ctrlArea = (ProfileTxtContentCtrl)base.FindName("ctrlArea");
			this.btnSendInvite = (Button)base.FindName("btnSendInvite");
			this.btnExpose = (Button)base.FindName("btnExpose");
		}
	}
}
